﻿<%@ WebHandler Language="C#" Class="img_update" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Collections.Generic;
using System.Web.SessionState;

public class img_update : IHttpHandler, IRequiresSessionState
{
    sqlhelp sql = new sqlhelp();
    result result = new result();
    string str = "";
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }
            string Linkid = "";
            if (context.Request["Linkid"] != null)
            {
                Linkid = context.Request["Linkid"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递官网Linkid参数";
                unit.send(context, result);
                return;
            }
            string imgPath = "";
            if (context.Request["imgPath"] != null)
            {
                imgPath = context.Request["imgPath"].ToString();
            }
            else
            {
                result.code = "0";
                result.msg = "未传递官网imgPath参数";
                unit.send(context, result);
                return;
            }

            str = "delete from SYS_Image where Linkid = '" + Linkid + "'";
            sql.ExecuteNonQuery(str);
            string[] imgList = imgPath.Split(',');
            for (int i = 0; i < imgList.Length; i++)
            {
                string imgID = Guid.NewGuid().ToString();
                if (imgList[i] != "")
                {
                    str = "insert into SYS_Image(Id,Linkid,Path,CreateTime,Enable) values('" + imgID + "','" + Linkid + "','" + imgList[i] + "','" + DateTime.Now.ToString() + "',1)";
                    sql.ExecuteNonQuery(str);
                }

            }
            result.code = "1";
            result.msg = "";

        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }
        unit.send(context, result);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}